//
//  YLDisplayAmountDescriptionView.m
//  YLFinanceService
//
//  Created by she1323 on 2017/9/4.
//  Copyright © 2017年 she1323. All rights reserved.
//  金额显示说明

#import "YLDisplayAmountDescriptionView.h"
#import "YLGlobeHeader.h"
#import <Masonry.h>

@interface YLDisplayAmountDescriptionView ()
@property (nonatomic, weak) UIView *baseView;

@property (nonatomic, weak) UILabel *titleLabel;
@property (nonatomic, weak) UILabel *contentLabel;

@end

@implementation YLDisplayAmountDescriptionView


- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        [self setUp];
        self.backgroundColor = YLColorA(0, 0, 0, 0.8);
    }
    return self;
}

- (void)setUp
{
    __weak typeof(self) weakSelf = self;
    UIView *baseView = [[UIView alloc] init];
    _baseView = baseView;
    baseView.backgroundColor = [UIColor whiteColor];
    baseView.layer.masksToBounds = YES;
    baseView.layer.cornerRadius = 5.0;
    [self addSubview:baseView];
    [baseView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.mas_equalTo(weakSelf);
        make.left.mas_equalTo(weakSelf).mas_equalTo(40);
        make.right.mas_equalTo(weakSelf).mas_equalTo(-40);
    }];
    
    UILabel *titleLabel = [[UILabel alloc] init];
    [baseView addSubview:titleLabel];
    titleLabel.font = [UIFont boldSystemFontOfSize:17];
    _titleLabel = titleLabel;
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(40);
        make.centerX.mas_equalTo(baseView);
        make.top.mas_equalTo(baseView.mas_top).mas_offset(10);
        
    }];
    
    UIView *line = [[UIView alloc] init];
    line.backgroundColor = YLLOrgColor;
    line.alpha = 0.4;
    [baseView addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(weakSelf);
        make.height.mas_equalTo(1);
        make.top.mas_equalTo(titleLabel.mas_bottom);
    }];
    
    UIImageView *closeImageView = [[UIImageView alloc] init];
    closeImageView.image = [UIImage imageNamed:@"close"];
    [baseView addSubview:closeImageView];
    [closeImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(titleLabel).mas_equalTo(13);
        make.height.width.mas_equalTo(12.5);
        make.right.mas_equalTo(baseView).mas_equalTo(-10);
    }];
    
    UILabel *contentLabel = [[UILabel alloc] init];
    [contentLabel setTextColor:[UIColor darkGrayColor]];
    contentLabel.numberOfLines = 0;
    contentLabel.font = [UIFont systemFontOfSize:15.0f];
    _contentLabel = contentLabel;
    [baseView addSubview:contentLabel];
    [contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(line).mas_offset(15);
        make.left.mas_equalTo(baseView).mas_equalTo(15);
        make.right.bottom.mas_equalTo(baseView).mas_equalTo(-15);
    }];
    
    
    
    
    
}

- (void)setType:(YLDisplayAmountDescriptionViewType)type
{
    _type = type;
    
    if (_type == YLDisplayAmountDescriptionViewTypeAmount) {
        _contentLabel.text = @"为保障您的合法权益，我们对您的每一笔订单都有严格的审核及管理备案机制，因此订单明细、预期收益等将会出现相对延迟的现象，这对您的实际合法权益不会产生任何影响。随着业务流转，账户数据将会持续更新，敬请关注！";
        _titleLabel.text = @"金额显示说明";
    } else if (_type == YLDisplayAmountDescriptionViewTypeBankCard) {
        _titleLabel.text = @"银行卡更换事项";
        _contentLabel.text = @"银行卡更换只需要您重新认证本人银行卡即可，请注意只能认证储蓄卡，信用卡暂时无法提供认证。";
    }
}


- (void)didMoveToSuperview
{
    __weak typeof(self) weakSelf = self;
   
    self.alpha = 0;
    [UIView animateWithDuration:0.3 animations:^{
        weakSelf.alpha = 1;
    }];
   
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [self removeFromSuperview];
}





@end
